/********************************************
 *      
 * Created by zlj on 2024/9/21.
********************************************/

#ifndef DATA_STRUCTURE_MEMERY_H
#define DATA_STRUCTURE_MEMERY_H
#include "stdlib.h"
#include "stdint.h"
#include "stdio.h"
#include "stdalign.h"
typedef struct mp_large_s{
    struct mp_large_s *next;
    void *alloc;
}mp_large_s;

typedef struct mp_node_s{
    unsigned char *last;
    unsigned char *end;
    struct mp_node_s *next;
} mp_node_s;

typedef struct mp_pool_s{
    size_t max;
    struct mp_node_s *current; //指向当前使用的小内存块
    struct mp_large_s *large;  //大内存块
    struct mp_node_s head[0];
} mp_pool_s;


struct mp_pool_s *mp_create_pool(size_t size);

void mp_destory_pool(struct mp_pool_s *pool);

void *mp_alloc(struct mp_pool_s *pool, size_t size);

void *mp_nalloc(struct mp_pool_s *pool, size_t size);

void *mp_calloc(struct mp_pool_s *pool, size_t size);

void mp_free(struct mp_pool_s *pool, void *p);

#endif //DATA_STRUCTURE_MEMERY_H
